import 'package:flutter/material.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:provider/provider.dart';
import 'package:s_mankey/config/net/smonkey_api.dart';
import 'package:s_mankey/config/resource_mananger.dart';
import 'package:s_mankey/config/storage_manager.dart';
import 'package:s_mankey/model/banner_model.dart';
import 'package:s_mankey/provider/provider_widget.dart';
import 'package:s_mankey/service/smonkey_repository.dart';
import 'package:s_mankey/ui/widget/show_toast.dart';
import 'package:s_mankey/view_model/banner_demo_vmodel.dart';
import 'package:s_mankey/view_model/home_vmodel.dart';


class HomeSwiperDemo extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return ProviderWidget<BnnaerDemoVModel>(model: BnnaerDemoVModel(),onModelReady: (model) => model.initDatas(),
      builder: (context, model ,child){

        if(model.isError) {
//          print('model.viewStateError.toString()${model.viewStateError.message.toString()}');
        Toast.toast(context,msg: '${model.viewStateError.message.toString()}');
        Toast.toast(context,msg: '我我我');
          return Text('${model.viewStateError.message.toString()}');
        }

        if(model.isEmpty) {
          return Text('数据是空的');
        }

        if(model.isBusy){
          return Text('正在加载中');
        }

        print('数据是:${model.datas}');

        if(model.datas.code != 0){
          return Text(model.datas.message);
        }

        BannerModel datas = BannerModel.fromJson(model.datas.data);
        return

          PhysicalModel(
            borderRadius: BorderRadius.circular(20),
            clipBehavior: Clip.antiAlias,
            color: Colors.transparent,
            child: Container(
              padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
              height: 150,
              child:
              Swiper(
                itemCount: datas.list.length,
                autoplayDelay: 3000,
                autoplay: false,
                pagination: new SwiperPagination(
                    builder: DotSwiperPaginationBuilder(
                      color: Colors.black54,
                      activeColor: Colors.white,
                    )),
//                  loop: true,
                itemBuilder: (BuildContext context, int index) {
                  return new Image.network(
                    datas.list[index].imageUrl,
                    fit: BoxFit.fill,
                  );
                },
                onTap: (index){
                  print('点击了第$index张图片');
                },
              ),
            ),
          );
      },);
  }
}